package com.example.nsl


import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.transition.ChangeBounds
import android.transition.Fade
import android.transition.TransitionSet
import android.transition.TransitionSet.ORDERING_SEQUENTIAL
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewConfiguration
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.OnApplyWindowInsetsListener
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.nsl.R.*


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(R.layout.test)
//        setContentView(R.layout.activity_main)
        setContentView(layout.test1)
        initLayout()
        window.statusBarColor=Color.TRANSPARENT

        // First apply the insets listener


    }



    fun initLayout() {
        val recyclerView=findViewById<RecyclerView>(id.recyclerview)
        val layoutroot=findViewById<View>(id.layoutroot)
        recyclerView.layoutManager= LinearLayoutManager(this).apply {
            orientation=LinearLayoutManager.HORIZONTAL
            this
        }
        recyclerView.adapter=object :RecyclerView.Adapter<RecyclerView.ViewHolder>(){
            override fun onCreateViewHolder(
                parent: ViewGroup,
                viewType: Int
            ): RecyclerView.ViewHolder {
                return  CustomViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item, parent, false))
            }

            override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
                if(position%2==0){
                    holder.itemView.setBackgroundColor(Color.RED)
                }else{
                    holder.itemView.setBackgroundColor(Color.BLUE)
                }
            }

            override fun getItemCount(): Int {
                 return 9;
            }

            //自定义ViewHolder
            inner class CustomViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

            }
        }
//        ViewCompat.setOnApplyWindowInsetsListener(recyclerView
//        ) { _, insets -> insets!! }

//        layoutroot.rotation=-180f
    }


    private fun init() {

        val TouchSlop = ViewConfiguration.get(applicationContext).scaledTouchSlop
        val FlingVe = ViewConfiguration.get(applicationContext).scaledMinimumFlingVelocity
        val getScaledPagingTouchSlop = ViewConfiguration.get(applicationContext).scaledPagingTouchSlop

        Log.e("onTouchEvent TouchSlop", "TouchSlop:$TouchSlop  FlingVe:$FlingVe")
        Log.e("onTouchEvent TouchSlop", "getScaledPagingTouchSlop:$getScaledPagingTouchSlop")

        var view=findViewById<View>(id.view);
        var view1=findViewById<View>(id.view1);
//        var Shape= RoundRectShape()
        val background =  GradientDrawable() //获取对应的shape实例

        background.setColor(Color.RED) //设置为绿色
        background.setStroke(10,Color.RED) //设置为绿色

        background.cornerRadius = 20f //设置圆角

//        var arcshape=ArcShape(0f,26f)     //float startAngle, float sweepAngle
//        val shape=ShapeDrawable(arcshape)

        view.setBackgroundDrawable(background)
//        background.setColor(Color.YELLOW) //设置为绿色
//        view1.setBackgroundDrawable(background)
//        CoordinatorLayout
//        Handler(Looper.getMainLooper()).post {
//            arcshape.startAngle=arcshape.startAngle+5f
//        }


//        GestureDetector
//        Scroller


        val set = TransitionSet()

        set.setOrdering(ORDERING_SEQUENTIAL)
        set.addTransition(Fade(Fade.OUT)).addTransition(ChangeBounds()).addTransition(Fade(Fade.IN))
    }


}